package truef.comment.web.spring.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import edu.zut.cs.software.base.web.spring.controller.GenericController;
import truef.comment.domain.Comment;
import truef.service.comment.service.CommentManager;

@Controller
//拦截含有comment的url并处理
@RequestMapping("/comment")//1.
public class CommentController extends GenericController<Comment, Long, CommentManager> {
	CommentManager commentManager;

	/*
	 * 部署成功后，在浏览器中输入url
	 * http://localhost:8080/universalStore-web/${1.}/${2.value值}
	 * 例子:http://localhost:8080/universalStore-web/comment/index.html
	*/
	@RequestMapping(value="/index.html" ,method=RequestMethod.GET)//2.
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView();
		List<Comment> commentList = commentManager.findAll(); 
		//与WEB-INF/pages中视图地址保持一致
		mv.setViewName("comment/index");
		mv.addObject("commentList",commentList);
		return mv;
	}

	@Autowired
	public void setUserManager(CommentManager commentManager) {
		this.commentManager = commentManager;
		this.manager = this.commentManager;
	}

}
